using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Runtime.Serialization;
using CoreData;
using Helper;
namespace OpenIDHostController.DataContract
{
    [DataContract]
    public class groupsContract
    {
        [DataMember]
            public long id{get;set;}
        [DataMember]
            public string name{get;set;}
        [DataMember]
            public string description{get;set;}
        [DataMember]
            public bool active{get;set;}

        public groupsContract()
        {       
                    name ="";   
                    description ="";   
        }

        public static groupsContract ToContract(groups data)
        {
            try
            {
                var model = ConvertObject.ConvertToObject(new groupsContract());
                Helper.ConvertObject.ConvertEntityToModel(data, ref model);
                return (groupsContract)model;
            }
            catch
            {
                return null;
            }
        }

        public static groups ToCoreData(groupsContract data)
        {
            try
            {
                var model = ConvertObject.ConvertToObject(new groups());
                Helper.ConvertObject.ConvertEntityToModel(data, ref model);
                return (groups)model;
            }
            catch
            {
                return null;
            }
        }

        public static IList<groups> ToListCoreData(IList<groupsContract> data)
        {
            var list = new List<groups>();
            foreach (var item in data)
            {
                var model = ConvertObject.ConvertToObject(new groups());
                Helper.ConvertObject.ConvertEntityToModel(item, ref model);
                if (model != null)
                {
                    list.Add((groups)model);
                }
            }
            if (list.Count <= 0)
                return null;
            return list;
        }

        public static IList<groupsContract> ToListConTract(IList<groups> data)
        {
            var list = new List<groupsContract>();
            foreach (var item in data)
            {
                var model = ConvertObject.ConvertToObject(new groupsContract());
                Helper.ConvertObject.ConvertEntityToModel(item, ref model);
                if (model != null)
                {
                    list.Add((groupsContract)model);
                }
            }
            if (list.Count <= 0)
                return null;
            return list;
        }
        
    }
}
